package com.cetcs.kmga.dataManager.service.impl.device;

import com.alibaba.fastjson.JSON;
import com.cetc.cloud.kmga.util.HttpUtil;
import com.cetc.cloud.kmga.util.MqUtil;
import com.cetcs.kmga.common.Data;
import com.cetcs.kmga.common.Page;
import com.cetcs.kmga.dataManager.dao.mybatis.CodeTableManagerMapper;
import com.cetcs.kmga.dataManager.dao.mybatis.DeviceConfigMenuMapper;
import com.cetcs.kmga.dataManager.dao.mybatis.DeviceLoginParamsMapper;
import com.cetcs.kmga.dataManager.dao.mybatis.DeviceManagerMapper;
import com.cetcs.kmga.dataManager.entity.device.*;
import com.cetcs.kmga.dataManager.entity.device.vo.*;
import com.cetcs.kmga.dataManager.entity.global.DeviceMqMessage;
import com.cetcs.kmga.dataManager.global.DataManagerConstants;
import com.cetcs.kmga.dataManager.schedule.InitCdTypeListener;
import com.cetcs.kmga.dataManager.service.device.AuditService;
import com.cetcs.kmga.dataManager.service.device.DeviceManagerService;
import com.cetcs.kmga.dataManager.util.MqParamsUtil;
import com.cetcs.kmga.dataManager.util.ReadConfigUtil;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.google.common.collect.Lists;
import deviceservice.core.DevManager;
import deviceservice.entity.DataSource;
import deviceservice.entity.result.Result;
import deviceservice.utils.CryptoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by yyangs on 2017/2/14.
 */
@Service
public class DeviceManagerServiceImpl implements DeviceManagerService{
    // 重新加载 内存数据库
    @Autowired
    private InitCdTypeListener initCdTypeListener;
    @Autowired
    private DeviceManagerMapper deviceManagerMapper;
    @Autowired
    private CodeTableManagerMapper codeTableManagerMapper;
    @Autowired
    private AuditService auditService;
    @Autowired
    private DeviceConfigMenuMapper deviceConfigMenuMapper;
    @Autowired
    private DeviceLoginParamsMapper deviceLoginParamsMapper;

    @Override
    public DeviceInfo getDeviceInfoById(Data dataMap) throws Exception {
        return deviceManagerMapper.getDeviceInfoById(dataMap);
    }

    @Override
    public List<DeviceInfo> getDeviceInfosByCondition(Data dataMap) throws Exception {
        return deviceManagerMapper.getDeviceInfosByCondition(dataMap);
    }

    @Override
    public Page getDeviceInfosByPageAndCondition(Data dataMap) throws Exception {
        List<DeviceInfo> resultList = Lists.newArrayList();
        resultList = deviceManagerMapper.getDeviceInfosByCondition(dataMap, new PageBounds(dataMap.getInt("page"), dataMap.getInt("pageSize")));
        PageList<DeviceInfo> pageList = (PageList<DeviceInfo>) resultList;
        return new Page(pageList);
    }

    /**
     * 添加设备
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public Integer createDeviceInfo(Data dataMap) throws Exception {

        //获取登录日至系统的用户名密码 配置文件中
        String log_admin = ReadConfigUtil.getValueByKey("conf\\logService.properties","log_admin");
        String log_password = ReadConfigUtil.getValueByKey("conf\\logService.properties","log_password");
        String log_url = ReadConfigUtil.getValueByKey("conf\\logService.properties","log_url");
        /**
         * 获取 设备类型的 标识符
         */
        Data params = new Data();
        String typeIdentifier = "";
        params.put("id",dataMap.getString("type"));
        dataMap.put("id",dataMap.getString("type"));
        List<DeviceTypeIdentifier> typeIdentifiers = codeTableManagerMapper.getAllDeviceTypeIdentifiersByCondition(params);
        if(typeIdentifiers.size()>0){
            typeIdentifier = typeIdentifiers.get(0).getIdentifier();
            dataMap.put("type",typeIdentifiers.get(0).getType());
        }
        params.clear();
        String manufacturerIdentifier = "";
        params.put("id",dataMap.getString("manuf"));
        List<DeviceManufacturerIdentifier> deviceManufacturerIdentifiers = codeTableManagerMapper.getAllDeviceManufacturerIdentifiersByCondition(params);
        if(deviceManufacturerIdentifiers.size()>0){
            manufacturerIdentifier = deviceManufacturerIdentifiers.get(0).getIdentifier();
            dataMap.put("manuf",deviceManufacturerIdentifiers.get(0).getManufacturer());
        }
        if(!"30".equals(dataMap.getString("id"))) {
            dataMap.put("url", "http://" + dataMap.getString("ip") + manufacturerIdentifier + typeIdentifier);
        }else{
            dataMap.put("url", "https://" + dataMap.getString("ip") + manufacturerIdentifier + typeIdentifier);
        }
        String flag = "30".equals(dataMap.getString("id"))? new HttpUtil("www").APPLICATION_FORM_URLENCODED:new HttpUtil("www").APPLICATION_JSON;
        Result addDevResult = DevManager.addDevice(flag,Integer.parseInt(dataMap.getString("id")),dataMap.getString("usr"),dataMap.getString("password"),dataMap.getString("url"),log_url,6,log_admin,log_password);
            if(addDevResult.isResult()) {
            dataMap.put("token",addDevResult.getAccessToken());
            dataMap.put("id",addDevResult.getDevID());
            //密码加密 根据设备ID加密
            dataMap.put("password",CryptoUtil.aesEncrypt(dataMap.getString("password"),CryptoUtil.hash(addDevResult.getDevID())));
            //注册时间
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            dataMap.put("regTime", simpleDateFormat.format(new Date()));
            //校验是否存在 通过唯一id
            params.clear();
            params.put("id",addDevResult.getDevID());
            Integer isExist = deviceManagerMapper.isExistDevice(params);
            if(isExist <= 0) {
                Integer result = deviceManagerMapper.createDeviceInfo(dataMap);
                if(result>0){
                    // 如果 添加成功 写入MQ队列
                    DeviceMqMessage deviceMqMessage = new DeviceMqMessage();
                    List<String> list = Lists.newArrayList();
                    list.add(addDevResult.getDevID());
                    deviceMqMessage.setDevNums(list);
                    deviceMqMessage.setTime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
                    deviceMqMessage.setType("Add");
                    MqUtil.getInstance(MqParamsUtil.getMqHost(),MqParamsUtil.getMqUser(),MqParamsUtil.getMqPwd()).sendBroacastMsg2Exch("dev.fanout",JSON.toJSONString(deviceMqMessage));
                    initCdTypeListener.reloadDevicesIn2CodeTb();
                }
                return result;
            }else{
                throw new Exception("设备已存在，请勿重复添加！");
            }
        }else{
            return 0;
        }
    }

    @Override
    public Integer updateDeviceInfo(Data dataMap) throws Exception {
        Integer result = 0;
        /**
         * 获取 设备类型的 标识符
         */
        Data params = new Data();
        params.put("id",dataMap.getString("type"));
        List<DeviceTypeIdentifier> typeIdentifiers = codeTableManagerMapper.getAllDeviceTypeIdentifiersByCondition(params);
        if(typeIdentifiers.size()>0){
            dataMap.put("type",typeIdentifiers.get(0).getType());
        }
        params.clear();
        params.put("id",dataMap.getString("manuf"));
        List<DeviceManufacturerIdentifier> deviceManufacturerIdentifiers = codeTableManagerMapper.getAllDeviceManufacturerIdentifiersByCondition(params);
        if(deviceManufacturerIdentifiers.size()>0){
            dataMap.put("manuf",deviceManufacturerIdentifiers.get(0).getManufacturer());
        }
        result = deviceManagerMapper.updateDeviceInfo(dataMap);
        if(result>0) {
            initCdTypeListener.reloadDevicesIn2CodeTb();
        }
        return result;
//        Data params = new Data();
//        params.put("name",dataMap.get("name"));
//        Integer isExist = deviceManagerMapper.isExistDevice(params);
//        if(isExist <= 0) {
//            return deviceManagerMapper.updateDeviceInfo(dataMap);
//        }else{
//            throw new Exception("设备名称重复，请修改名称！");
//        }
    }

    @Override
    public Integer deleteDeviceInfo(Data dataMap) throws Exception {
        DeviceInfo deviceInfo = deviceManagerMapper.getDeviceInfoById(dataMap);
        //根据id获取设备信息
        String flag = "运维设备".equals(deviceInfo.getType())? DataManagerConstants.APPLICATION_FORM_URLENCODED:DataManagerConstants.APPLICATION_JSON;
        Boolean result = DevManager.fill(flag,deviceInfo.getUrl(),deviceInfo.getToken(),deviceInfo.getId(),"delete");
        if(result) {
            // 如果 删除成功 写入MQ队列 发送MQ消息
            DeviceMqMessage deviceMqMessage = new DeviceMqMessage();
            List<String> list = Lists.newArrayList();
            list.add(dataMap.getString("id"));
            deviceMqMessage.setDevNums(list);
            deviceMqMessage.setTime(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
            deviceMqMessage.setType("Del");
            MqUtil.getInstance(MqParamsUtil.getMqHost(),MqParamsUtil.getMqUser(),MqParamsUtil.getMqPwd()).sendBroacastMsg2Exch("dev.fanout",JSON.toJSONString(deviceMqMessage));
            Integer flags = 0;
            flags = deviceManagerMapper.deleteDeviceInfo(dataMap);
            if(flags>0) {
                initCdTypeListener.reloadDevicesIn2CodeTb();
            }
            return flags;
        }else{
            throw new Exception("删除失败");
        }
    }

    /**
     * 批量删除
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public Integer batchDeleteDevice(Data dataMap) throws Exception {
        List<String> ids = (List<String>) dataMap.get("ids");
        Integer result = 0;
        for(String id:ids){
            Data params = new Data();
            params.put("id",id);
            result = deleteDeviceInfo(params);
        }
        initCdTypeListener.reloadDevicesIn2CodeTb();
        return result;
    }

    /**
     * 判断设备是否已经存在
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public Integer isExistDevice(Data dataMap) throws Exception {
        return deviceManagerMapper.isExistDevice(dataMap);
    }

    /**
     * 通过条件 获取不同类型的设备数量
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public DeviceSummaryQuantityVo getDeviceNumByType(Data dataMap) throws Exception {
        DeviceSummaryQuantityVo deviceSummaryQuantityVo = new DeviceSummaryQuantityVo();
        DeviceNumberVo probe = new DeviceNumberVo();
        probe.setName("探针设备");
        DeviceNumberVo desensitization = new DeviceNumberVo();
        desensitization.setName("脱敏设备");
        DeviceNumberVo ops = new DeviceNumberVo();
        ops.setName("运维设备");
        //获得当前的所有的数量
        List<DeviceNumber> totalLists = deviceManagerMapper.getTotalNumByTypeAndCondition(dataMap);
        for(DeviceNumber deviceNumber:totalLists){
            switch (deviceNumber.getDeviceTypeName()){
                case "探针设备":probe.setTotal(deviceNumber.getDeviceNum());break;
                case "脱敏设备":desensitization.setTotal(deviceNumber.getDeviceNum());break;
                case "运维设备":ops.setTotal(deviceNumber.getDeviceNum());break;
                default: break;
            }
        }
//        //获得当前非正常运行状态的设备
//        List<DeviceNumber> isActivelists = deviceManagerMapper.getNotActiveNumByTypeAndCondition(dataMap);
//        for(DeviceNumber deviceNumber:isActivelists){
//            switch (deviceNumber.getDeviceTypeName()){
//                case "探针设备":probe.setRunning(probe.getTotal()-deviceNumber.getDeviceNum());break;
//                case "脱敏设备":desensitization.setRunning(desensitization.getTotal()-deviceNumber.getDeviceNum());break;
//                case "运维设备":ops.setRunning(ops.getTotal()-deviceNumber.getDeviceNum());break;
//                default: break;
//            }
//        }
        //获得当前正常运行状态的设备
        dataMap.put("status",2);
        List<DeviceNumber> isActivelists = deviceManagerMapper.getTotalNumByTypeAndCondition(dataMap);
        for(DeviceNumber deviceNumber:isActivelists){
            switch (deviceNumber.getDeviceTypeName()){
                case "探针设备":probe.setRunning(deviceNumber.getDeviceNum());break;
                case "脱敏设备":desensitization.setRunning(deviceNumber.getDeviceNum());break;
                case "运维设备":ops.setRunning(deviceNumber.getDeviceNum());break;
                default: break;
            }
        }
        if(probe.getRunning()==null){
            probe.setRunning(0);
        }
        deviceSummaryQuantityVo.setProbe(probe);
        if(desensitization.getRunning()==null){
            desensitization.setRunning(0);
        }
        deviceSummaryQuantityVo.setDesensitization(desensitization);
        if(ops.getRunning()==null){
            ops.setRunning(0);
        }
        deviceSummaryQuantityVo.setOps(ops);
        return deviceSummaryQuantityVo;
    }

    /**
     * 获得相应的设备拓扑图
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public TopologyVo getDevicesTopologyByCondition(Data dataMap) throws Exception {
        TopologyVo topologyVo = new TopologyVo();
        List<DeviceTopologyVo> probe = Lists.newArrayList();
        List<DeviceTopologyVo> desensitization = Lists.newArrayList();
        List<DeviceTopologyVo> ops = Lists.newArrayList();

        //获得所有的设备的当前状态
        List<DeviceInfo> deviceInfos = deviceManagerMapper.getDeviceInfosAndStatusByCondition(dataMap);
        for(DeviceInfo deviceInfo:deviceInfos){
            DeviceTopologyVo deviceTopologyVo = new DeviceTopologyVo();
            deviceTopologyVo.setId(deviceInfo.getId());
            deviceTopologyVo.setName(deviceInfo.getName());
            /**
             * 设备状态
             */
            deviceTopologyVo.setType(Integer.parseInt(deviceInfo.getStatus()));
//            if(Integer.parseInt(deviceInfo.getStatus()) > 1){
//                //正常
//                deviceTopologyVo.setType(Integer.parseInt(deviceInfo.getStatus())-1);
//            }else{
//                //离线
//                deviceTopologyVo.setType(Integer.parseInt(deviceInfo.getStatus()));
//            }
            switch (deviceInfo.getType()){
                case "探针设备":probe.add(deviceTopologyVo);break;
                case "脱敏设备":desensitization.add(deviceTopologyVo);break;
                case "运维设备":ops.add(deviceTopologyVo);break;
                default: break;
            }
        }

        topologyVo.setProbe(probe);
        topologyVo.setDesensitization(desensitization);
        topologyVo.setOps(ops);

        return topologyVo;
    }

    /**
     * 获取设备类型
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public List<DeviceTypeIdentifier> getAllDeviceType(Data dataMap) throws Exception {
        return codeTableManagerMapper.getAllDeviceTypeIdentifiersByCondition(dataMap);
    }

    /**
     * 获取设备厂商
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public List<DeviceManufacturerIdentifier> getAllDeviceManufacturer(Data dataMap) throws Exception {
        return codeTableManagerMapper.getAllDeviceManufacturerIdentifiersByCondition(dataMap);
    }

    /**
     * 获取数据资源
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public Integer createDataResource(Data dataMap) throws Exception {



//        //1. 获取所有的探针设备
//        Data params = new Data();
//        params.put("type","脱敏设备");
//        List<DeviceInfo> deviceInfos = deviceManagerMapper.getDeviceInfosByCondition(params);
//        Integer result = 0;
//        //循环调用接口 获取数据
//        for(DeviceInfo deviceInfo:deviceInfos){
//            List<Object> dataSources =  DevManager.query(deviceInfo.getUrl(),deviceInfo.getToken(),deviceInfo.getId(),"datasource");
//            //根据 数据库名称和版本号 查询审计类型
//            for(Object object:dataSources){
//                DataSource dataSource = (DataSource)object;
//                //获取到的资源名称和资源版本号 查询 审计类型
//                if(dataSource.getDbType()!=null){
//                    //审计名称不为空
//                    params.clear();
//                    params.put("value",dataSource.getDbType());
//                    DeviceAuditObjTypevers deviceAuditObjTypevers = codeTableManagerMapper.getDeviceAuditObjTypeversByCondition(params);
//                    if(deviceAuditObjTypevers!=null){
//                        if(deviceAuditObjTypevers.getType()==1){
//                            //如果类型为1 则添加至待确定的资源审计日志
//                            /**
//                             * 添加之前都先要进行数据的判断是否已经存在
//                             */
//                            params.clear();
//                            params.put("resrcTypeCode",deviceAuditObjTypevers.getResrcType());
//                            params.put("type",deviceAuditObjTypevers.getType());
//                            params.put("desc",dataSource.getDbType());
//                            params.put("serverIp",dataSource.getIpString());
//                            params.put("port",dataSource.getPort());
//                            params.put("src",0);
//                            params.put("name",dataSource.getAuditObjName());
//                            params.put("stat",dataSource.getState());
//                            params.put("uploadTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//                            result += auditService.createOrUpdateResrcAuditObjNocnct(params);
//                        }else{
//                            //其他的则为 数据资源信息和数据资源审计对象信息
//                            /**
//                             * 添加之前都先要进行数据的判断是否已经存在
//                             */
//                            params.clear();
//                            params.put("resrcTypeCode",deviceAuditObjTypevers.getResrcType());
//                            params.put("name",""+deviceAuditObjTypevers.getResrcType()+"_"+dataSource.getIpString());
//                            params.put("vers",dataSource.getDbVersion());
//                            params.put("serverIp",dataSource.getIpString());
//                            params.put("desc",dataSource.getDbType());
//                            params.put("src",0);
//                            params.put("supevLevel",3);
//                            params.put("uploadTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//                            //生成ID
//                            params.put("id",Math.abs((""+deviceAuditObjTypevers.getResrcType().toUpperCase()+dataSource.getDbVersion()+dataSource.getIpString().replace(".","")).hashCode()));
//                            result = auditService.createOrUpdateResrc(params);
//                            params.put("resrcId",params.getInt("id"));
//                            params.put("id",Math.abs(("" + dataSource.getIpString().replace(".","")+dataSource.getPort()).hashCode()));
//                            params.put("port",dataSource.getPort());
//                            params.put("type",deviceAuditObjTypevers.getType());
//                            params.put("stat",dataSource.getState());
//                            params.put("name",dataSource.getAuditObjName());
//                            result += auditService.createOrUpdateResrcAuditObj(params);
//                        }
//                    }
//                }
//            }
//        }
//        return result;
//        //获取所有的设备信息 然后 每个设备获取其审计接口数据
//        Data params = new Data();
//        List<DeviceInfo> deviceInfos = deviceManagerMapper.getDeviceInfosByCondition(params);
//        Integer result = 0;
//        //循环调用接口 获取数据
//        for(DeviceInfo deviceInfo:deviceInfos){
//            List<Object> dataSources =  DevManager.query(deviceInfo.getUrl(),deviceInfo.getToken(),deviceInfo.getId(),"datasource");
//            //根据 数据库名称和版本号 查询审计类型
//            for(Object object:dataSources){
//                DataSource dataSource = (DataSource)object;
//                //获取到的资源名称和资源版本号 查询 审计类型
//                //根据获取到的审计信息 ip 端口 来源 判断是否已经存在
//                Integer isExist
//                // 已经存在修改更新时间
//                // 不存在加入未知对象中
//
//                if(dataSource.getDbType()!=null){
//                    //审计名称不为空
//                    String auditObjName;
//                    Integer state;
//                    String dbType;
//                    String dbVersion;
//                    String ipString;
//                    Integer port;
//                }
//            }
//        }
        return null;
    }



    /**
     * 获取设备的状态信息--折线图
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public DeviceStatusInfoVo getDeviceStatusInfoById(Data dataMap) throws Exception {
        DeviceStatusInfoVo deviceStatusInfoVo = new DeviceStatusInfoVo();
        //封装基本信息
        Data params = new Data();
        params.put("id",dataMap.get("id"));
        DeviceInfo deviceInfo = deviceManagerMapper.getDeviceInfoById(params);
        deviceStatusInfoVo.setName(deviceInfo.getName());
        deviceStatusInfoVo.setType(deviceInfo.getType());
        deviceStatusInfoVo.setPhone(deviceInfo.getAdminPhone());
        deviceStatusInfoVo.setIp(deviceInfo.getIp());
        deviceStatusInfoVo.setLinkMan(deviceInfo.getAdminName());
        deviceStatusInfoVo.setLocation(deviceInfo.getLocation());
        //封装折线图
        List<DeviceStatusLineChart> deviceStatusLineCharts = deviceManagerMapper.getDeviceStatusLineChart(dataMap);
        DeviceStatusLinesVo deviceStatusLinesVo = new DeviceStatusLinesVo();
        List<String> dateX = Lists.newArrayList();
        List<String> cpuData = Lists.newArrayList();
        List<String> memoryData = Lists.newArrayList();
        List<String> diskUseData = Lists.newArrayList();
        List<String> ioInfoInData = Lists.newArrayList();
        List<String> ioInfoOutData = Lists.newArrayList();
        for(DeviceStatusLineChart deviceStatusLineChart : deviceStatusLineCharts){
            dateX.add(deviceStatusLineChart.getTime());
            cpuData.add(deviceStatusLineChart.getCpuRate());
            memoryData.add(deviceStatusLineChart.getMemUsed());
            diskUseData.add(deviceStatusLineChart.getDiskUsed());
            ioInfoInData.add(deviceStatusLineChart.getNetIn());
            ioInfoOutData.add(deviceStatusLineChart.getNetOut());
        }
        //封装折线图
        deviceStatusLinesVo.setDateX(dateX);
        //cpu
        DeviceStatusChartsVo cpu = new DeviceStatusChartsVo();
        cpu.setName("CPU使用率");
        cpu.setDataY(cpuData);
        deviceStatusLinesVo.setCpu(cpu);
        //内存
        DeviceStatusChartsVo mem = new DeviceStatusChartsVo();
        mem.setName("内存使用率");
        mem.setDataY(memoryData);
        deviceStatusLinesVo.setMemory(mem);
        //磁盘
        DeviceStatusChartsVo disk = new DeviceStatusChartsVo();
        disk.setName("磁盘使用率");
        disk.setDataY(diskUseData);
        deviceStatusLinesVo.setDiskUse(disk);
        //io
        DeviceIOStatusVo io = new DeviceIOStatusVo();
        DeviceStatusChartsVo ioIn = new DeviceStatusChartsVo();
        ioIn.setName("IO写入");
        ioIn.setDataY(ioInfoInData);
        io.setIn(ioIn);
        DeviceStatusChartsVo ioOut = new DeviceStatusChartsVo();
        ioOut.setName("IO输出");
        ioOut.setDataY(ioInfoOutData);
        io.setOut(ioOut);
        deviceStatusLinesVo.setIoInfo(io);
        deviceStatusInfoVo.setLineS(deviceStatusLinesVo);

        return deviceStatusInfoVo;
    }

    /**
     * 获取设备配置菜单
     * @param dataMap
     * @return
     * @throws Exception
     */
    @Override
    public List<DeviceConfigMenuVo> getDeviceConfigMenuById(Data dataMap) throws Exception {
        //先查询 该设备的信息  获取他的设备类型 和 设备IP
        DeviceInfo deviceInfo = deviceManagerMapper.getDeviceInfoById(dataMap);
        Data params = new Data();
        switch (deviceInfo.getType()){
            case "探针设备":params.put("type",1);break;
            case "脱敏设备":params.put("type",2);break;
            case "运维设备":params.put("type",3);break;
            default: throw new Exception("数据出错");
        }
        List<DeviceConfigMenu> deviceConfigMenus = deviceConfigMenuMapper.getAllDeviceConfigMenuByCondition(params);
        //然后根据设备类型获取设备的菜单 替换url
        List<DeviceConfigMenuVo> deviceConfigMenuVos = Lists.newArrayList();
        for(DeviceConfigMenu deviceConfigMenu:deviceConfigMenus){
            DeviceConfigMenuVo deviceConfigMenuVo = new DeviceConfigMenuVo();
            deviceConfigMenuVo.setName(deviceConfigMenu.getName());
            deviceConfigMenuVo.setUrl(deviceConfigMenu.getUrl().replace("localhost",deviceInfo.getIp()));
            deviceConfigMenuVos.add(deviceConfigMenuVo);
        }
        return deviceConfigMenuVos;
    }

    /**
     * 获取设备登录的参数
     * @param dataMap deviceId
     * @return
     * @throws Exception
     */
    @Override
    public List<DeviceLoginParams> getDeviceLoginParamsByDeviceID(Data dataMap) throws Exception {
        return deviceLoginParamsMapper.getDeviceLoginParamsByDeviceID(dataMap);
    }

}
